STEP2_BIN_DEP:= fsimginfo.py step2.asm step2_logprint.asm step2_readdisk.asm step2_findbootbin.asm
STEP3_BIN_DEP:= unrealmodegdt.py step3.asm step2_logprint.asm

all: gen_fs.img
		qemu-system-x86_64 -drive file=gen_fs.img,format=raw -m 2048 -monitor stdio

gen_fs.img: step2 step3
		dd if=gen_step2.bin of=gen_disk.raw bs=512 count=1 conv=notrunc
		dd if=gen_disk.raw of=$@ bs=1 count=448 seek=62 conv=notrunc
		@if [ ! -d "mnt" ]; then \
        sudo mkdir -p mnt; \
        	echo "Created mnt directory"; \
    	else \
        	echo "mnt directory already exists"; \
    	fi
		sudo mount gen_fs.img mnt
		sudo cp gen_step3.bin mnt/BOOTBIN
		sudo sync
		sudo umount mnt


step2: $(STEP2_BIN_DEP)
		python3 $(word 1,$^)
		nasm $(word 2,$^) -f bin -o gen_step2.bin

step3: $(STEP3_BIN_DEP)
		python3 $(word 1,$^) 0x10000
		nasm $(word 2,$^) -f bin -o gen_step3.bin


clean: 
	rm gen_* -f
	